package pwd.allen.construct.flyweight;

import pwd.allen.construct.common.MysqlConnection;

/**
 * @author lenovo
 * @create 2021-05-21 16:47
 **/
public class Main {
    public static void main(String[] args) {
        FlyWeightFactory factory = new FlyWeightFactory();
        IFlyWeight flyWeight = null;

        // 将IConnection共享的对象（连接地址等）抽到享元角色里
        flyWeight = factory.getFlyWeight("127.0.0.1:3333/test");
        flyWeight.operation(new MysqlConnection());
        // 返回已创建过的享元对象，相同的资源无须在创建
        flyWeight = factory.getFlyWeight("127.0.0.1:3333/test");
        flyWeight.operation(new MysqlConnection());
    }
}
